package kku.cs.sidescroll;

import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;

import kku.cs.fgl.SpriteManager;
import kku.cs.fgl.actor.SpriteActor;

public class FireManActor extends SpriteActor {
    int floor=300;
    
    public FireManActor(SpriteManager sprites) {
       super(sprites);
       setAnimate(true);
    }
    int dtime=0;
    @Override    
    public void calculateSpeed(int time) {
        dtime+=time;
        if(dtime>500 && getSpeed_y()==0){
          setSpeed_x(0);
          dtime=0;
        }
        if (input.isKeyDown(Input.KEY_LEFT)) runLeft();
        if (input.isKeyDown(Input.KEY_RIGHT))runRight();
        if (input.isKeyDown(Input.KEY_UP))   jump();
        if (input.isKeyDown(Input.KEY_DOWN))  sit();
        if(getY()<floor){
           setSpeed_y(getSpeed_y()+0.05f);
        }
        if(getY()>floor){
           setY(floor);
           setSpeed_y(0);
        }        
        if(getSpeed_y()!=0){
            setKeyName("jump");             
        }
        if(getSpeed_x()==0 && getSpeed_y()==0){
           setKeyName("stand");            
        }
        if (input.isKeyDown(Input.KEY_SPACE))shoot();
       // super.calculateSpeed(time);
    }
    void sit() {
        if(getSpeed_y()==0){
            setSpeed_x(0);
            setKeyName("sit");                               
        }        
    }
    void shoot() {
        setKeyName("shoot");                   
        setSpeed_x(0);
    }
    void jump() {
        if(getSpeed_y()==0){
          setSpeed_y(-2);
        }
    }
    void runRight() {
        if(getSpeed_y()==0){
         setSpeed_x(2);
         setKeyName("run");
         setHflip(false);
        }
    }
    void runLeft() {
        if(getSpeed_y()==0){
         setSpeed_x(-2);
         setKeyName("run");
         setHflip(true);       
        }
    }
   
}
